<template>
  <section class="app-inner">
    <el-dialog
      :title="addTeachForm.title"
      :visible.sync="addTeachForm.flag"
      width="70%"
      modal
      center
      top="5vh"
      :before-close="close"
      :show-close="true"
    >
      <div style="position: relative">
        <el-tabs v-model="activeName">
          <el-tab-pane label="基本信息" name="1" class="info-school-tab">
            <el-form
              ref="teachForm"
              :model="infoForm"
              label-width="140px"
              :rules="rules"
              size="small"
            >
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="教职工名称" prop="name">
                    <el-input
                      placeholder="请输入教职工名称"
                      v-model="infoForm.name"
                      clearable
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="工号" prop="number">
                    <el-input
                      placeholder="请输入工号"
                      v-model="infoForm.number"
                      clearable
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系方式" prop="contact">
                    <Acc-desensitization ref="cellularPhone" rule-type='cellularPhone' v-model="infoForm.contact"></Acc-desensitization>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="所属部门" prop="deptNo">
                    <depart-tree
                      v-model="infoForm.deptNo"
                      :departments="deptData"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否默认生成账号" prop="isCreateAccount">
                    <el-select
                      placeholder="请选择"
                      filterable
                      v-model="infoForm.isCreateAccount"
                      :disabled="
                        addTeachForm.title === '编辑教职工信息' ? true : false
                      "
                    >
                      <el-option
                        v-for="item in createAccountOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item
                    label="账号"
                    prop="account"
                  >
                    <!-- :rules="[
                      {
                        required: infoForm.isCreateAccount === 1 ? true : false,
                        message: '请输入账号',
                        trigger: 'blur',
                      },
                    ]" -->
                    <el-input
                      :disabled="isDisableAccount"
                      placeholder="请输入账号"
                      v-model="infoForm.account"
                      clearable
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="所属校区" prop="schoolDistrictNo">
                    <el-select
                      placeholder="请输入所属校区"
                      filterable
                      v-model="infoForm.schoolDistrictNo"
                      clearable
                    >
                      <el-option
                        v-for="item in schoolOptions"
                        :key="item.no"
                        :label="item.name"
                        :value="item.no"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="性别" prop="gender">
                    <el-select
                      :disabled="infoForm.cardType === '1'"
                      placeholder="请选择性别"
                      filterable
                      v-model="infoForm.gender"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['性别']"
                        :key="item.code"
                        :label="item.name"
                        :value="Number(item.code)"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="国籍" prop="nationality">
                    <el-select
                      placeholder="请选择国籍"
                      filterable
                      v-model="infoForm.nationality"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['国籍']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="证件类型" prop="cardType">
                    <el-select
                      placeholder="请选择证件类型"
                      filterable
                      v-model="infoForm.cardType"
                      clearable
                      @change="handleChangeCardType"
                    >
                      <el-option
                        v-for="item in infoData['证件']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="证件号码" prop="idCard">
                    <Acc-desensitization
                      ref="AccDesensitization"
                      :isdesensitization="infoForm.cardType === '1'"
                      @blur="blurSearchIdInfo"
                      v-model="infoForm.idCard"
                    ></Acc-desensitization>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="出生日期" prop="birthday">
                    <el-date-picker
                      :disabled="infoForm.cardType === '1'"
                      :picker-options="pickerOptions"
                      format="yyyy-MM-dd"
                      value-format="yyyy-MM-dd"
                      v-model="infoForm.birthday"
                      type="date"
                      style="width: 100%"
                      placeholder="出生日期"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="岗位类别" prop="positionType">
                    <el-select
                      placeholder="请选择岗位类型"
                      filterable
                      v-model="infoForm.positionType"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['教职工岗位']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="籍贯" prop="nativePlace">
                    <el-cascader
                      :disabled="infoForm.cardType === '1'"
                      style="width: 100%"
                      separator=""
                      filterable
                      :options="regionOptions"
                      v-model="infoForm.nativePlace"
                    >
                    </el-cascader>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="出生地" prop="birthPlace">
                    <el-cascader
                      :disabled="infoForm.cardType === '1'"
                      style="width: 100%"
                      separator=""
                      filterable
                      :options="regionOptions"
                      v-model="infoForm.birthPlace"
                    >
                    </el-cascader>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="婚姻状况">
                    <el-select
                      placeholder="请选择婚姻状况"
                      filterable
                      v-model="infoForm.maritalStatus"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['婚姻']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="民族">
                    <el-select
                      placeholder="请选择民族"
                      filterable
                      v-model="infoForm.nationCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['民族']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="政治面貌">
                    <el-select
                      placeholder="请选择政治面貌"
                      filterable
                      v-model="infoForm.politicsStatus"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['政治']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="港澳台侨">
                    <el-select
                      placeholder="请选择港澳台侨"
                      filterable
                      v-model="infoForm.compatriotCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['港澳台']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="宗教信仰">
                    <el-select
                      placeholder="请选择宗教信仰"
                      filterable
                      v-model="infoForm.religionCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['宗教']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="健康状况">
                    <el-select
                      placeholder="请选择健康状况"
                      filterable
                      v-model="infoForm.healthCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['健康']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="血型">
                    <el-select
                      placeholder="请选择血型"
                      filterable
                      v-model="infoForm.bloodTypeCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['血型']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="最高学历">
                    <el-select
                      placeholder="请选择最高学历"
                      filterable
                      v-model="infoForm.educationBackground"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['学历']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="最高学位">
                    <el-select
                      placeholder="请选择最高学位"
                      filterable
                      v-model="infoForm.lastDegree"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['学位']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="最高学历获取学校">
                    <el-input
                      placeholder="请输入最高学历获取学校"
                      v-model="infoForm.graduateSchool"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="最高学位获取学校">
                    <el-input
                      placeholder="请输入最高学位获取学校"
                      v-model="infoForm.lastDegreeSchool"
                    ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="其他信息" name="2" class="info-school-tab">
            <el-form
              ref="form"
              :model="infoForm"
              label-width="140px"
              size="small"
            >
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="参加工作年月">
                    <el-date-picker
                      :picker-options="pickerOptions"
                      format="yyyy-MM"
                      value-format="yyyy-MM"
                      v-model="infoForm.workDate"
                      type="month"
                      style="width: 100%"
                      placeholder="选择参加工作年月"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="进入本校年月">
                    <el-date-picker
                      :picker-options="pickerOptions"
                      format="yyyy-MM"
                      value-format="yyyy-MM"
                      v-model="infoForm.hereDate"
                      type="month"
                      style="width: 100%"
                      placeholder="选择进入本校年月"
                    >
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="教职工来源">
                    <el-select
                      placeholder="请选择教职工来源"
                      filterable
                      v-model="infoForm.sourceCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['教职工来源']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="教职工类别">
                    <el-select
                      placeholder="请选择教职工类别"
                      filterable
                      v-model="infoForm.typeCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['教职工类别']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="是否在编">
                    <el-select
                      placeholder="请选择"
                      filterable
                      v-model="infoForm.isAuthorized"
                      clearable
                    >
                      <el-option
                        v-for="item in permanentStates"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="用人性质">
                    <el-select
                      placeholder="请选择用人性质"
                      filterable
                      v-model="infoForm.staffType"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['教职工用人形式']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="合同性质">
                    <el-select
                      placeholder="请选择合同性质"
                      filterable
                      v-model="infoForm.isSign"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['教职工合同']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="岗位等级">
                    <el-select
                      placeholder="请选择岗位等级"
                      filterable
                      v-model="infoForm.positionLevel"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['岗位等级']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="专业职务">
                    <el-select
                      placeholder="请选择专业职务"
                      filterable
                      v-model="infoForm.duty"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['专业技术职务']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="在岗情况">
                    <el-select
                      placeholder="请选择在岗情况"
                      filterable
                      v-model="infoForm.positionStatus"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['教职工在岗情况']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="户口性质">
                    <el-select
                      placeholder="请选择户口"
                      filterable
                      v-model="infoForm.residenceCode"
                      clearable
                    >
                      <el-option
                        v-for="item in infoData['户口']"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      >
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="户口所在地">
                    <el-cascader
                      style="width: 100%"
                      separator=""
                      filterable
                      :options="regionOptions"
                      v-model="infoForm.residenceLocation"
                    >
                    </el-cascader>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="户口地址">
                    <el-input
                      placeholder="请输入户口地址"
                      v-model="infoForm.residenceAddress"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="居住地址">
                    <el-input
                      placeholder="请输入居住地址"
                      v-model="infoForm.currentResidentialAddress"
                    ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="员工照片">
                    <el-upload
                      :class="{ 'pic-card': infoForm.imageUrl }"
                      action="/gateway/api/basic/minio/upload"
                      list-type="picture-card"
                      :limit="1"
                      :fileList="infoForm.imageUrl ? fileList : []"
                      :on-remove="handleAvatarRemove"
                      :on-success="handleAvatarSuccess"
                      :before-upload="beforeAvatarUpload"
                    >
                      <i v-if="!infoForm.imageUrl" class="el-icon-plus" />
                    </el-upload>
                    <div v-if="!infoForm.imageUrl" class="img-tip">
                      <b>员工照片</b>
                      <span>（请上传照片，10M以内）</span>
                    </div>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-tab-pane>
        </el-tabs>
        <div
          v-if="
            addTeachForm.title !== '新增教职工信息'
          "
          class="switch-btn cursor iconfont"
          :class="[isShow ? 'icon-yanjing' : 'icon-biyan']"
          @click="handleClickIsShow"
        ></div>
      </div>
      <div class="foot">
        <el-button type="default" @click.native.prevent="close()"
          >取消</el-button
        >
        <el-button type="primary" @click.native.prevent="sub()">保存</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import { Message } from 'element-ui'
import {
  queryNativePlace,
  addTeacher,
  updateTeach
} from '@/views/children/basic/js/teacherInfo'
import { getIdCardInfo } from '@/api/user'
import { getSchoolAreaNameList } from '@/views/children/basic/js/schoolAreaInfo.js'
import { validatePhone } from '@/utils/validate'
import DepartTree from './departTree'
import { encrypt } from '@/utils/crypto'
// 教职工表单校验
const rules = {
  name: [
    { required: true, message: '请输入教职工名称', trigger: 'blur' },
    { max: 30, message: '教职工名称长度不能超过30个字符', trigger: 'blur' }
  ],
  number: [
    { required: true, message: '请输入工号', trigger: 'blur' },
    { max: 30, message: '工号长度不能超过30个字符', trigger: 'blur' }
  ],
  contact: [{ required: true, trigger: 'blur', validator: validatePhone }],
  // gender: [{ required: true, message: '请选择性别', trigger: 'change' }],
  nationality: [{ required: true, message: '请选择国籍', trigger: 'change' }],
  cardType: [
    { required: true, message: '请选择身份证类别', trigger: 'change' }
  ],
  idCard: [{ required: true, message: '请输入身份证号码', trigger: 'blur' }]
  // birthday: [{ required: true, message: '请输入出生日期', trigger: 'blur' }]
  // positionType: [
  //   { required: true, message: '请选择岗位类别', trigger: 'change' }
  // ]
  // nativePlace: [{ required: true, message: '请输入籍贯', trigger: 'blur' }]
}

export default {
  name: 'addSchoolInfo',
  inject: ['handleSearch'],
  components: { DepartTree },
  props: {
    addTeachForm: {
      type: Object
    },
    data: {
      type: Object
    },
    infoData: {
      type: Object
    },
    deptData: {
      type: Array
    }
  },
  data () {
    return {
      isShow: true,
      activeName: '1',
      // 基础表单校验规则
      rules,
      content: '',
      isClear: false, // 清除富文本编辑器内容
      dialogVisible: false,
      options: [],
      schoolOptions: [], // 校区选项
      fileList: [
        {
          url: ''
        }
      ],
      // 是否在编
      permanentStates: [
        {
          label: '是',
          value: 0
        },
        {
          label: '否',
          value: 1
        }
      ],
      createAccountOptions: [
        { label: '是', value: 1 },
        { label: '否', value: 0 }
      ],
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      // 表单信息默认数据
      infoForm: {
        account: '', // 账号
        isCreateAccount: 1, // 账号状态
        birthPlace: [], // 出生地
        birthday: '', // 出生日期
        bloodTypeCode: '', // 血型
        cardType: '', // 身份证类型
        compatriotCode: '', // 港澳台侨
        contact: '', // 联系方式
        currentResidentialAddress: '',
        deptNo: '',
        duty: '',
        educationBackground: '',
        gender: null, // 性别
        graduateSchool: '',
        healthCode: '',
        hereDate: '',
        idCard: '',
        isAuthorized: 0,
        isSign: '',
        lastDegree: '',
        lastDegreeSchool: '',
        maritalStatus: '',
        imageUrl: '',
        name: '',
        nationCode: '',
        nationality: '',
        nativePlace: [],
        number: '',
        politicsStatus: '',
        positionLevel: '',
        positionStatus: '',
        positionType: '',
        religionCode: '',
        residenceAddress: '',
        residenceCode: '',
        residenceLocation: [],
        schoolDistrictNo: '',
        sourceCode: '',
        staffType: '',
        typeCode: '',
        workDate: ''
      },
      regionOptions: []
    }
  },
  computed: {
    isDisableAccount () {
      return (
        (this.infoForm && !this.infoForm.isCreateAccount) ||
        this.addTeachForm.title === '编辑教职工信息'
      )
    },
    phone () {
      return this.infoForm && this.infoForm.contact
    }
  },
  watch: {
    phone () {
      if (
        this.addTeachForm.title === '新增教职工信息' &&
        this.infoForm &&
        this.infoForm.isCreateAccount
      ) {
        this.$set(this.infoForm, 'account', this.phone)
      }
    },
    isDisableAccount () {
      if (
        this.isDisableAccount &&
        this.addTeachForm.title === '新增教职工信息'
      ) {
        this.$set(this.infoForm, 'account', '')
      }
    }
  },
  created () {
    this.infoForm = this.data
    this.fileList[0].url = `/gateway/api/basic/minio/getFileSource?fileName=${this.infoForm.imageUrl}`
  },
  methods: {
    handleClickIsShow () {
      this.isShow = !this.isShow
      this.$refs.AccDesensitization.doShow()
      this.$refs.cellularPhone.doShow()
    },
    blurSearchIdInfo () {
      if (this.infoForm.cardType !== '1' || this.infoForm.idCard === '') return
      getIdCardInfo({ encryptParam: encrypt(this.infoForm.idCard) }).then(
        (res) => {
          const { data } = res
          if (data.age === -1) return this.$message.warning(data.birthDay)
          this.$set(this.infoForm, 'nativePlace', data.nativePlace.split(','))
          this.$set(this.infoForm, 'birthPlace', data.nativePlace.split(','))
          this.$set(this.infoForm, 'birthday', data.birthDay)
          this.$set(this.infoForm, 'gender', data.gender)
        }
      )
    },
    handleChangeCardType () {
      this.infoForm.idCard.length === 18 && this.blurSearchIdInfo()
      // this.infoForm.nativePlace = ''
      // this.infoForm.birthPlace = ''
      // this.infoForm.birthday = ''
    },
    // 关闭弹框
    close () {
      this.$refs['teachForm'].resetFields()
      this.infoForm.deptNo = ''
      this.$emit('closeaddTeachForm', false)
      this.activeName = '1'
      this.handleSearch()
    },
    setRegion (region) {
      return region && region.length ? region.join(',') : ''
    },
    // 修改保存信息
    sub () {
      this.$refs['teachForm'].validate((valid) => {
        if (valid) {
          const params = {
            account: this.infoForm.account,
            isCreateAccount: this.infoForm.isCreateAccount,
            birthPlace: this.setRegion(this.infoForm.birthPlace),
            birthday: this.infoForm.birthday,
            bloodTypeCode: this.infoForm.bloodTypeCode,
            cardType: this.infoForm.cardType,
            compatriotCode: this.infoForm.compatriotCode,
            contact: this.infoForm.contact,
            currentResidentialAddress: this.infoForm.currentResidentialAddress,
            deptNo: this.infoForm.deptNo,
            duty: this.infoForm.duty,
            educationBackground: this.infoForm.educationBackground,
            gender: this.infoForm.gender,
            graduateSchool: this.infoForm.graduateSchool,
            healthCode: this.infoForm.healthCode,
            hereDate: this.infoForm.hereDate
              ? this.infoForm.hereDate + '-01'
              : null,
            id: this.infoForm.id,
            idCard: this.infoForm.idCard,
            imageUrl: this.infoForm.imageUrl,
            isAuthorized: this.infoForm.isAuthorized,
            isSign: this.infoForm.isSign,
            lastDegree: this.infoForm.lastDegree,
            lastDegreeSchool: this.infoForm.lastDegreeSchool,
            maritalStatus: this.infoForm.maritalStatus,
            name: this.infoForm.name,
            nationCode: this.infoForm.nationCode,
            nationality: this.infoForm.nationality,
            nativePlace: this.setRegion(this.infoForm.nativePlace),
            number: this.infoForm.number,
            politicsStatus: this.infoForm.politicsStatus,
            positionLevel: this.infoForm.positionLevel,
            positionStatus: this.infoForm.positionStatus,
            positionType: this.infoForm.positionType,
            religionCode: this.infoForm.religionCode,
            residenceAddress: this.infoForm.residenceAddress,
            residenceCode: this.infoForm.residenceCode,
            residenceLocation: this.setRegion(this.infoForm.residenceLocation),
            schoolDistrictNo: this.infoForm.schoolDistrictNo,
            sourceCode: this.infoForm.sourceCode,
            staffType: this.infoForm.staffType,
            typeCode: this.infoForm.typeCode,
            workDate: this.infoForm.workDate
              ? this.infoForm.workDate + '-01'
              : null
          }
          if (this.addTeachForm.title === '新增教职工信息') {
            addTeacher({ encryptParam: encrypt(params) }).then((res) => {
              if (res.code === 0) {
                this.$message.success('新增成功')
                this.close()
              }
            })
          } else if (this.addTeachForm.title === '编辑教职工信息') {
            updateTeach({ encryptParam: encrypt(params) }).then((res) => {
              if (res.code === 0) {
                this.$message.success('修改成功')
                this.close()
              }
            })
          }
        } else {
          return false
        }
      })
    },
    handleAvatarSuccess (res, file) {
      if (res.code === 0 && res.data) {
        this.$set(this.infoForm, 'imageUrl', res.data)
        this.fileList[0].url = `/gateway/api/basic/minio/getFileSource?fileName=${this.infoForm.imageUrl}`
        Message({
          message: '上传头像成功',
          type: 'success',
          customClass: 'mzindex'
        })
      } else {
        this.$set(this.infoForm, 'imageUrl', '')
        Message({
          message: res.msg,
          type: 'error',
          customClass: 'mzindex'
        })
      }
    },
    handleAvatarRemove () {
      this.infoForm.imageUrl = ''
    },
    beforeAvatarUpload (file) {
      const isJPG =
        file.type === 'image/jpeg' ||
        file.type === 'image/bmp' ||
        file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 10

      if (!isJPG) {
        this.$set(this.infoForm, 'imageUrl', '')
        Message({
          message: '上传员工照片只能是 JPG、PNG、BMP 格式!',
          type: 'error',
          customClass: 'mzindex'
        })
        return false
      }

      if (!isLt2M) {
        this.$set(this.infoForm, 'imageUrl', '')
        Message({
          message: '上传员工照片大小不能超过 10MB!',
          type: 'error',
          customClass: 'mzindex'
        })
        return false
      }
      return isJPG && isLt2M
    },
    async getSchoolList () {
      const res = await getSchoolAreaNameList()
      if (res.code === 0) {
        this.schoolOptions = res.data
      }
    },
    async getRegionData () {
      const regiondata = require('@/assets/region/region.json')
      try {
        const res = await queryNativePlace({
          type: 'ALL'
        })
        if (res.code === 0) {
          this.regionOptions = this.setRegiondata(res.data)
        }
      } catch (e) {
        this.regionOptions = this.setRegiondata(regiondata)
      }
    },
    setRegiondata (region) {
      // 处理省市区接口返回数据添加指定字段
      if (Array.isArray(region) && region.length) {
        region.map((n) => {
          n.label = n.name
          n.value = n.adcode
          if (n.children && n.children.length) {
            this.setRegiondata(n.children)
          }
        })
      }
      return region
    }
  },
  mounted () {
    this.getSchoolList()
    this.getRegionData()
  }
}
</script>

<style lang="scss" scoped>
.switch-btn {
  width: 50px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  font-size: 20px;
  position: absolute;
  right: 0;
  top: 5px;
}
.mzindex {
  z-index: 3000 !important;
}

.img-tip {
  width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.app-inner {
  /deep/ .foot {
    text-align: center;

    > * {
      margin: 20px 80px;
    }
  }

  .info-school-tab {
    .el-select,
    .el-select--small {
      width: 100%;
    }
  }

  ::v-deep {
    .pic-card {
      .el-upload--picture-card {
        display: none;
      }
    }
  }
}
</style>
